package com.mc.web;

import org.apache.log4j.Logger;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import com.mc.model.Department;
import com.mc.model.Path;
import com.mc.model.Teacher;
import com.mc.model.Teachertype;
import com.mc.model.Teteacherytpe;
import com.mc.model.data_download;
import com.mc.service.IDataService;
import com.mc.service.IDepartmentService;
import com.mc.service.MajorService;
import com.mc.service.TeacherService;
import com.mc.service.TeachertypeService;
import com.mc.service.TeteachertypeService;
import com.mc.utils.PathUtil;

@Controller
@RequestMapping("/teacherdw")
public class TeacherDWAction {
	/**
	 * Logger for this class
	 */
	private static final Logger logger = Logger.getLogger(TeacherDWAction.class);

	private Path path = null;

	@Autowired private TeachertypeService teachertypeService;
	@Autowired private TeteachertypeService teteachertypeService;
	@Autowired private TeacherService teacherService;
	@Autowired private MajorService majorService;
	@Autowired private IDataService dataService;
	@Autowired private IDepartmentService departmentService;
	/**
	 * 师资队伍
	 * @param modelMap
	 * @return
	 */
	@RequestMapping("/teacherdwindex")
	public String bkpy(ModelMap modelMap)
	{
		List<Teteacherytpe> steachers = teteachertypeService.selectAllsteacher();
		modelMap.addAttribute("steachers", steachers);
		
		List<Teteacherytpe> yxteachers = teteachertypeService.selectAllyxteacher();
		modelMap.addAttribute("yxteachers", yxteachers);
		
		List<Teacher> cteachers = teacherService.selectAllcteachers();
		modelMap.addAttribute("cteachers", cteachers);
		
		List<Teacher> rteachers = teacherService.selectAllrteachers();
		modelMap.addAttribute("rteachers", rteachers);
		
		List<Teacher> xteachers = teacherService.selectAllxteachers();
		modelMap.addAttribute("xteachers", xteachers);
		
		List<Teacher> yteachers = teacherService.selectAllyteachers();
		modelMap.addAttribute("yteachers", yteachers);
		
		List<Teacher> wteachers = teacherService.selectAllwteachers();
		modelMap.addAttribute("wteachers", wteachers);
		path = PathUtil.setPathParams(new String[]{"PackageName:TeacherDW","ViewName:shiziduiwu","ViewTitle:师资队伍","smenu:teacherdw","mmenu:teacherdwindex"});				
		return PathUtil.returnStr(path, modelMap);
	}
	/**
	 * 
	 * @param id  教师id
	 * @param modelMap 
	 * @return 显示展示信息
	 */
	@RequestMapping("/detail/{id}")
	public String detail(@PathVariable("id")int id,ModelMap modelMap)
	{
		List<data_download> downlodData = dataService.selectLimit();
	   // logger.info(downlodData.size());
    	modelMap.addAttribute("downloadData",downlodData);
		Teacher teacher = teacherService.selectByPrimaryKey(id);
		modelMap.addAttribute("teacher",teacher);
		path = PathUtil.setPathParams(new String[]{"PackageName:TeacherDW","ViewName:detail","ViewTitle:老师介绍","smenu:teacherdw","mmenu:teacherintro"});		
        
		return PathUtil.returnStr(path, modelMap);
	}
	
	/**
	 * 
	 * @param modelMap
	 * @return 教学团队
	 */
	@RequestMapping("/jxindex")
	public String type(ModelMap modelMap){
		List<Department> departments = departmentService.selectbydtype("教学机构");
		List<List<Teacher>> teachers = new ArrayList<List<Teacher>>();
		for(Iterator<Department> iterator=departments.iterator();iterator.hasNext();){
			Department department = iterator.next();
			//logger.info(department.getdId());
			List<Teacher> teacher = teacherService.selectbydid(department.getdId());
			//logger.info(teacher.toString());
			teachers.add(teacher);
		}
		//logger.info(departments.size());
		//logger.info(teachers.get(1).toString());
		modelMap.addAttribute("departments", departments);
		modelMap.addAttribute("teachers", teachers);
		path = PathUtil.setPathParams(new String[]{"PackageName:TeacherDW","ViewName:jstd","ViewTitle:教学团队","smenu:teacherdw","mmenu:teacherdwindex"});				
		return PathUtil.returnStr(path, modelMap);
	}
	/**
	 * 
	 * @param modelMap
	 * @return 优秀名师
	 */
	@RequestMapping("/yxrcindex")
	public String yxrc(ModelMap modelMap){
		List<Teachertype> types = teachertypeService.selectnjssd();
		List<List<Teacher>> teachers = new ArrayList<List<Teacher>>();
		for(Iterator<Teachertype> iterator=types.iterator();iterator.hasNext();){
			Teachertype type = iterator.next();
			//logger.info(department.getdId());
			List<Teacher> teacher = new ArrayList<Teacher>();
			List<Teteacherytpe> teteacher = teteachertypeService.selectallteacherteachertype(type.getId());
			//logger.info(teacher.toString());
			for(Iterator<Teteacherytpe> it = teteacher.iterator();it.hasNext();){
				Teteacherytpe teteacherytpe = it.next();
				teacher.add(teteacherytpe.gettId());
			}
			
			teachers.add(teacher);
		}
		//logger.info(departments.size());
		//logger.info(teachers.get(1).toString());
		modelMap.addAttribute("types", types);
		modelMap.addAttribute("teachers", teachers);
		path = PathUtil.setPathParams(new String[]{"PackageName:TeacherDW","ViewName:hbtd","ViewTitle:后备团队","smenu:teacherdw","mmenu:teacherdwindex"});				
		return PathUtil.returnStr(path, modelMap);
	}
	/**
	 * 
	 * @param modelMap
	 * @return 硕士生导师
	 */
	@RequestMapping("/sdindex")
	public String sds(ModelMap modelMap){
		List<Teachertype> types = teachertypeService.selectsd();
		List<List<Teacher>> teachers = new ArrayList<List<Teacher>>();
		for(Iterator<Teachertype> iterator=types.iterator();iterator.hasNext();){
			Teachertype type = iterator.next();
			//logger.info(department.getdId());
			List<Teacher> teacher = new ArrayList<Teacher>();
			List<Teteacherytpe> teteacher = teteachertypeService.selectallteacherteachertype(type.getId());
			//logger.info(teacher.toString());
			for(Iterator<Teteacherytpe> it = teteacher.iterator();it.hasNext();){
				Teteacherytpe teteacherytpe = it.next();
				teacher.add(teteacherytpe.gettId());
			}
			
			teachers.add(teacher);
		}
		//logger.info(departments.size());
		//logger.info(teachers.get(1).toString());
		modelMap.addAttribute("types", types);
		modelMap.addAttribute("teachers", teachers);
		path = PathUtil.setPathParams(new String[]{"PackageName:TeacherDW","ViewName:hbtd","ViewTitle:后备团队","smenu:teacherdw","mmenu:teacherdwindex"});				
		return PathUtil.returnStr(path, modelMap);
	}
	/**
	 * 
	 * @param modelMap
	 * @return 教授与副教授
	 */
	
	@RequestMapping("/jsindex")
	public String jss(ModelMap modelMap){
		List<Teachertype> types = teachertypeService.selectjs();
		List<List<Teacher>> teachers = new ArrayList<List<Teacher>>();
		for(Iterator<Teachertype> iterator=types.iterator();iterator.hasNext();){
			Teachertype type = iterator.next();
			//logger.info(department.getdId());
			List<Teacher> teacher = new ArrayList<Teacher>();
			List<Teteacherytpe> teteacher = teteachertypeService.selectallteacherteachertype(type.getId());
			//logger.info(teacher.toString());
			for(Iterator<Teteacherytpe> it = teteacher.iterator();it.hasNext();){
				Teteacherytpe teteacherytpe = it.next();
				teacher.add(teteacherytpe.gettId());
			}
			
			teachers.add(teacher);
		}
		//logger.info(departments.size());
		//logger.info(teachers.get(1).toString());
		modelMap.addAttribute("types", types);
		modelMap.addAttribute("teachers", teachers);
		path = PathUtil.setPathParams(new String[]{"PackageName:TeacherDW","ViewName:hbtd","ViewTitle:后备团队","smenu:teacherdw","mmenu:teacherdwindex"});				
		return PathUtil.returnStr(path, modelMap);
	}
}
